<h3>Locum Registration</h3>
<div id="popup_top"></div> 
<div id="popup_mid">
	<?php echo $form->create('Locum',array('action'=>'register','class'=>'splashForm','id'=>'pharmacyReg'));?>
	<table border="0" cellspacing="0" cellpadding="0">
	        <tr>
	            <td><?php echo $form->input('Username',array('label'=>false,'div'=>'', 'value'=>'Username')); ?></td>
	        </tr>
	        <tr><td>
	        	<input type="text" name="fakepassword" id="fakepassword" value="Password" onfocus="pwdFocus()" />
	        	<?php echo $form->password('Password',array('label'=>false,'div'=>'', 'style'=>'display:none;')); ?>
	        </td></tr>
	        <tr><td><?php echo $form->input('Email',array('label'=>false,'div'=>'', 'value'=>'Email')); ?></td></tr>
	        <tr><td><input id="pharmacyBtn" type="button" value="Register" class="pharmacyBtn" /></td></tr>
	</table>
	<?php 
	    echo $form->end();
	?>
	<div style="clear:both;"></div>
</div>
<div id="popup_bottom"></div>
<script>
    function v_fRemoveErrors()
    {
        $('#LocumUsername').focus(function(){
             $('#LocumUsername').parent().find('span').remove();
             if ( $(this).val() == "Username" )
		         $(this).val('');
        });
        
        $('#LocumPassword').focus(function(){
            $('#LocumPassword').parent().find('span').remove();
        });
        
        $('#LocumEmail').focus(function(){
             $('#LocumEmail').parent().find('span').remove();
             if ( $(this).val() == "Email" )
		         $(this).val('');
        });
    }
    function pwdFocus() {
        $('#fakepassword').hide();
        $('#LocumPassword').show();
        $('#LocumPassword').focus();
    }
    
    function v_fValidate()
    {
    	var Username = $('#LocumUsername').val();
    	if( Username == "" || Username == "Username" ){
        	alert('Please enter Username');
        	$('#LocumUsername').focus();
        	return false;
    	}
    	var Password = $('#LocumPassword').val();
    	if( Password == "" ){
        	alert('Please enter Password');
        	pwdFocus();
        	return false;
    	}
    	var Email = $('#LocumEmail').val();
    	if( Email == "" || Email == "Email" ){
        	alert('Please enter Email');
        	$('#LocumEmail').focus();
        	return false;
    	}
    	return true;
    }
    $(document).ready(function(){
    	
        v_fRemoveErrors();
       $('#pharmacyBtn').click(function(){
    	   if ( !v_fValidate())
        	   return false;
           $.ajax({
                type: 'POST',
                url: 'locums/save',
                data:$('form#pharmacyReg').serializeArray(),
                dataType: 'json',
                success: function(data){ 
                    if(data.success == 'faild')
                    {
                        if(data.Username)
                        {
                            $('#LocumUsername').parent().find('span').remove();
                            $('#LocumUsername').parent().prepend('<span class="error errors-register">'+data.Username+'</span>');
                        }
                        
                        if(data.Password)
                        {
                            $('#LocumPassword').parent().find('span').remove();
                            $('#LocumPassword').parent().prepend('<span class="error errors-register">'+data.Password + '</span>');
                        }
                        
                        if(data.Email)
                        {
                            $('#LocumEmail').parent().find('span').remove();
                            $('#LocumEmail').parent().prepend('<span class="error errors-register">'+data.Email+'</span>');
                        }
                    }else
                    {
                         jAlert(data, 'Message');
                         $('#LocumUsername').val('');
                         $('#LocumPassword').val('');
                         $('#LocumEmail').val('');
                        $('#modalTwo').hide();
                        $('.lb_overlay').remove();
                       
                    }
                },
                error: function(message){
                	 jAlert('Network connection errors', 'Message');
                }
                });
       });
    });
</script>